﻿using System.Xml.Linq;
using IcicleFramework.Components.Actions;
using IcicleFramework.Entities;
using IcicleFramework.GameServices;
using Microsoft.Xna.Framework;

namespace IcicleFramework.Components.Behaviors
{
    public abstract class BaseBehavior : IBehavior
    {
        public IBehaviorComponent Parent { get; set; }
        
        public IGameObject ParentGameObject
        {
            get { return Parent.Parent; }
        }

        public string Name { get; set; }

        public string ActionName { get; set; }

        public bool Paused { get; protected set; }

        protected ActionData actionData;

        protected BaseBehavior()
        {
            actionData = new ActionData();
        }

        protected BaseBehavior(BaseBehavior old)
        {
            this.ActionName = old.ActionName;
            actionData = new ActionData();
        }

        public virtual void Deserialize(XElement element)
        {
            XAttribute myName = element.Attribute("name");
            this.Name = myName != null ? myName.Value : string.Empty;
        }

        public void Pause()
        {
            Paused = true;
        }

        public void Resume()
        {
            Paused = false;
        }

        public virtual void Initialize() { }

        public virtual void PostInitialize() { }

        public virtual void Update(GameTime gameTime) { }

        public abstract IBehavior DeepClone();
    }
}
